package com.highspeed.bdk.controller.deploy;


import com.bianmaba.spring.data.jpa.domain.Result;
import com.bianmaba.spring.mvc.method.support.annotations.JSON;
import com.highspeed.bdk.bean.entity.deploy.DeployTopology;
import com.highspeed.bdk.controller.base.BdkCrudController;
import com.highspeed.bdk.service.base.IBdkBaseService;
import com.highspeed.bdk.service.deploy.IDeployTopologyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "deploy_topology", method = RequestMethod.POST)
@Api(tags = "部署拓扑")
public class DeployTopologyController extends BdkCrudController<DeployTopology, Integer> {
    @Autowired
    private IDeployTopologyService deployTopologyService;

    @Override
    protected IBdkBaseService<DeployTopology, Integer> getService() {
        return deployTopologyService;
    }

    @ApiOperation(value = "保存整个部署拓扑图", notes = "参数为JSON数据;<br/>" +
            "部署拓扑图中的acBindors用来描述物理拓扑图中的CPU与逻辑拓扑图中的APP的绑定关联，拓扑图中的连线是根据所有绑定的APP的链线来生成；")
    @JSON(excludeProperties = {"data.*\\.logicTopology", "data.*\\.preinstalledRedLogicTopology", "data.*\\.acBindors.*\\.machineBox", "data.*\\.acBindors.*\\.board"})
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @Override
    public Result save(@RequestBody @ApiParam(name = "entity") DeployTopology entity) {
        return super.save(entity);
    }

    @JSON
    @ApiOperation(value = "根据部署拓扑id查询所有虚线", notes = "拓扑图中的连线是根据所有绑定的APP的链线来生成")
    @ApiImplicitParam(name = "id", value = "部署拓扑id", dataType = "int", paramType = "query")
    @RequestMapping(value = {"/get_virtual_links_by_deploy_topology_id"}, method = RequestMethod.POST)
    public List<Map<String, Integer>> queryVirtualLinksByLogicTopologyId(Integer id) {
        return deployTopologyService.queryVirtualLinksByDeployTopologyId(id);
    }


    @JSON(excludeProperties = {"data.*\\.logicTopology", "data.*\\.preinstalledRedLogicTopology", "data.*\\.acBindors.*\\.machineBox", "data.*\\.acBindors.*\\.board"})
    @ApiOperation(
            value = "根据数据ID查询单个数据",
            notes = "如果指定ID的数据不存在，则返回NULL"
    )
    @ApiImplicitParam(
            name = "id",
            value = "查询",
            dataType = "int",
            paramType = "query"
    )
    @RequestMapping(
            value = {"/get_by_id"},
            method = {RequestMethod.POST}
    )
    @Override
    public Result getById(Integer id) {
        return super.getById(id);
    }
}
